// 最优组合
<template>
  <div class="tableAuto">
    <el-table :data="tableDataShow" style="width:100%" :height="height" @row-click="rowClick" border stripe
      :header-cell-style="{background:'#EAEBEC'}" v-loading="tableLoading" ref="refTable" highlight-current-row @sort-change='sortChange'>

      <el-table-column v-for="(item,index) in coluNames" :prop="`a`+index" width="140" show-overflow-tooltip :key="index"
        :label="item"></el-table-column>

      <!-- <el-table-column prop="mbx" min-width="160" show-overflow-tooltip :label="$t('model.target_col')"></el-table-column>
      <el-table-column prop="zyjlx" width="130" show-overflow-tooltip :label="$t('model.cpp_zyjlx')"></el-table-column>
      <el-table-column prop="cppmc" width="250" show-overflow-tooltip :label="$t('model.cpp_cppmc')"></el-table-column>
      <el-table-column prop="cppyj" width="140" show-overflow-tooltip :label="$t('model.cpp_cppyj')"></el-table-column> -->

      <!-- <el-table-column prop="zxxx" width="130" show-overflow-tooltip label="置信区间下限"></el-table-column>
      <el-table-column prop="zxsx" width="130" show-overflow-tooltip label="置信区间上限"></el-table-column>
      <el-table-column prop="ycxx" width="130" show-overflow-tooltip label="预测区间下限"></el-table-column>
      <el-table-column prop="ycsx" width="130" show-overflow-tooltip label="预测区间上限"></el-table-column> -->
    </el-table>
  </div>
</template>
<script>
export default {
  data () {
    return {
      radioId: "",
      height: document.body.offsetHeight - 210,

      wrList: [{
        label: "读写",
        value: 0
      }, {
        label: "只读",
        value: 1
      }, {
        label: "只写",
        value: 2
      }],
      coluNames: [],
      tableDataShow: [
        // { 'mbx': '水分含量', 'zyjlx': '最小值', 'cppmc': '温度', 'cppyj': '55', 'zxsx': '-2.06903', 'zxxx': '-1.22347', 'ycxx': '-2.06903', 'ycsx': '-1.22347', },
        // { 'mbx': '水分含量', 'zyjlx': '最小值', 'cppmc': '喂料量', 'cppyj': '1.0000026', 'zxsx': '55', 'zxxx': '55', 'ycxx': '55', 'ycsx': '55', },
        // { 'mbx': '水分含量', 'zyjlx': '最小值', 'cppmc': '风速', 'cppyj': '0.3', 'zxsx': '55', 'zxxx': '55', 'ycxx': '55', 'ycsx': '55', },
        // { 'mbx': '水分含量', 'zyjlx': '最小值', 'cppmc': '振动频率', 'cppyj': '42', 'zxsx': '55', 'zxxx': '55', 'ycxx': '55', 'ycsx': '55', },
      ],
    }
  },
  props: {
    tableData: Object,
    pager: Object,
    tableLoading: Boolean
  },
  watch: {
    tableData (val, oldValue) {
      this.tableDataShow = []
      this.coluNames = []
      for (let i in val) {
        this.coluNames.push(i)
      }
      for (let j = 0; j < val[this.coluNames[0]].length; j++) {
        let temp = {}
        for (let k = 0; k < this.coluNames.length; k++) {
          temp['a' + k] = val[this.coluNames[k]][j]
        }
        this.tableDataShow.push(temp)
      }
    }
  },
  methods: {
    rowClick (row) {
      this.radioId = row.woId;
      let obj = {
        row: row,
        radioId: this.radioId,
      }
      this.$emit("handleEdit", obj)
      this.$refs.refTable.setCurrentRow(row);
    },
    sortChange (column) {
      this.$emit('sortChange', column)
    },
    table_index (index) {
      return (this.pager.pageNum - 1) * this.pager.pageSize + index
    },
    getwrName (id) {
      if (!id && id !== 0) return ''
      return this.wrList.find(item => parseInt(item.value) == id).label
    },

  }
}
</script>
<style scoped>
.bai {
  color: #fff;
}
.tableAuto {
  margin-top: 10px;
}
</style>